package org.lottery.activity;

import org.lottery.entity.CardGraphicView;
import org.lottery.main.ImageAdapter;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class LotteryActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid_layout);
        // init settings
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String quantity = sharedPref.getString(SettingsActivity.SETTINGS_REWARD_QUANTITY, "");

        GridView gridView = (GridView) findViewById(R.id.grid_view);
        gridView.setAdapter(new ImageAdapter(this, Integer.parseInt(quantity)));
        gridView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {

                System.out.println(position);
                // flip card
                CardGraphicView cardBingo = ((CardGraphicView) v);
                if (cardBingo.isBingo()) {
                    cardBingo.setImageResource(R.drawable.bingo_paint);
                } else {
                    cardBingo.setImageResource(R.drawable.thumb1);
                }
                cardBingo.refreshDrawableState();
            }

        });
    }
}
